package util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import shopping.model.ProductType;
import shopping.model.ShoppingData;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationManager;
import android.util.DisplayMetrics;

import com.google.android.maps.GeoPoint;

public class Util {
	public static LocationManager LOCATIONMANAGER;
	public final static String DIR = "/sdcard/test/";
	public final static String Serializable_FILE = "sfile";
	public static List<ShoppingData> ALLDATA = new ArrayList<ShoppingData>();
	public static Map<String, ProductType> PRODUCT_TYPE_MAP;
	public static String ShoppingIDs = "IDs";
	public static DisplayMetrics DM = new DisplayMetrics();

	
	static {
		PRODUCT_TYPE_MAP = new HashMap<String, ProductType>();
		for (ProductType type : ProductType.values()) {
			switch (type) {
			case TYPE_CLOTHES:
				PRODUCT_TYPE_MAP.put("CLOTHES", type);
			case TYPE_TROUSERSE:
				PRODUCT_TYPE_MAP.put("TROUSERSE", type);
			case TYPE_UNDERWEAR:
				PRODUCT_TYPE_MAP.put("UNDERWEAR", type);
			case TYPE_SKIRT:
				PRODUCT_TYPE_MAP.put("SKIRT", type);
			default:
				;
			}
		}
	}

//	public static void save() {
//		FileOutputStream fs;
//		try {
//			fs = new FileOutputStream(Util.DIR + Util.Serializable_FILE);
//			ObjectOutputStream os = new ObjectOutputStream(fs);
//			for (ShoppingData data : ALLDATA) {
//				os.writeObject(data);
//			}
//			os.close();
//			fs.close();
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//	}
//
//	public static void load() {
//		FileInputStream fs;
//		try {
//			fs = new FileInputStream(Util.DIR + Util.Serializable_FILE);
//			ObjectInputStream os = new ObjectInputStream(fs);
//			while (os.available() > 0) {
//				ShoppingData data = (ShoppingData) os.readObject();
//				ALLDATA.add(data);
//			}
//			os.close();
//			fs.close();
//		} catch (FileNotFoundException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		} catch (ClassNotFoundException e) {
//			e.printStackTrace();
//		}
//	}

	public static GeoPoint location_to_geopoint(Location location) {
		return new GeoPoint((int) (location.getLatitude() * 1e6),
				(int) (location.getLongitude() * 1e6));
	}

	public static Drawable get_pic_by_id(String id) {
		Drawable drawable = Resources.getSystem().getDrawable(android.R.drawable.arrow_up_float);
		return drawable;
	}
}
